export default function(t, i) {
    "use strict";

    var n = n || {};
    n.Color = function(t) {
        this.autoUpdate = !0,
        this.setHex(t)
    }
    ,
    n.Color.prototype = {
        setRGBA: function(t, i, n, e) {
            this.r = t,
            this.g = i,
            this.b = n,
            this.a = e,
            this.autoUpdate && (this.updateHex(),
            this.updateStyleString())
        },
        setHex: function(t) {
            this.hex = t,
            this.autoUpdate && (this.updateRGBA(),
            this.updateStyleString())
        },
        copyRGB: function(t) {
            this.r = t.r,
            this.g = t.g,
            this.b = t.b
        },
        copyRGBA: function(t) {
            this.r = t.r,
            this.g = t.g,
            this.b = t.b,
            this.a = t.a
        },
        multiplySelfRGB: function(t) {
            this.r *= t.r,
            this.g *= t.g,
            this.b *= t.b
        },
        updateHex: function() {
            this.hex = Math.floor(255 * this.a) << 24 | Math.floor(255 * this.r) << 16 | Math.floor(255 * this.g) << 8 | Math.floor(255 * this.b)
        },
        updateRGBA: function() {
            this.a = (this.hex >> 24 & 255) / 255,
            this.r = (this.hex >> 16 & 255) / 255,
            this.g = (this.hex >> 8 & 255) / 255,
            this.b = (255 & this.hex) / 255
        },
        updateStyleString: function() {
            this.__styleString = "rgba(" + Math.floor(255 * this.r) + "," + Math.floor(255 * this.g) + "," + Math.floor(255 * this.b) + "," + this.a + ")"
        },
        toString: function() {
            return "THREE.Color ( r: " + this.r + ", g: " + this.g + ", b: " + this.b + ", a: " + this.a + ", hex: " + this.hex + " )"
        }
    },
    n.Vector2 = function(t, i) {
        this.x = t || 0,
        this.y = i || 0
    }
    ,
    n.Vector2.prototype = {
        set: function(t, i) {
            return this.x = t,
            this.y = i,
            this
        },
        copy: function(t) {
            return this.x = t.x,
            this.y = t.y,
            this
        },
        addSelf: function(t) {
            return this.x += t.x,
            this.y += t.y,
            this
        },
        add: function(t, i) {
            return this.x = t.x + i.x,
            this.y = t.y + i.y,
            this
        },
        subSelf: function(t) {
            return this.x -= t.x,
            this.y -= t.y,
            this
        },
        sub: function(t, i) {
            return this.x = t.x - i.x,
            this.y = t.y - i.y,
            this
        },
        multiplyScalar: function(t) {
            return this.x *= t,
            this.y *= t,
            this
        },
        unit: function() {
            return this.multiplyScalar(1 / this.length()),
            this
        },
        length: function() {
            return Math.sqrt(this.x * this.x + this.y * this.y)
        },
        lengthSq: function() {
            return this.x * this.x + this.y * this.y
        },
        negate: function() {
            return this.x = -this.x,
            this.y = -this.y,
            this
        },
        clone: function() {
            return new n.Vector2(this.x,this.y)
        },
        toString: function() {
            return "THREE.Vector2 (" + this.x + ", " + this.y + ")"
        }
    },
    n.Vector3 = function(t, i, n) {
        this.x = t || 0,
        this.y = i || 0,
        this.z = n || 0
    }
    ,
    n.Vector3.prototype = {
        set: function(t, i, n) {
            return this.x = t,
            this.y = i,
            this.z = n,
            this
        },
        copy: function(t) {
            return this.x = t.x,
            this.y = t.y,
            this.z = t.z,
            this
        },
        add: function(t, i) {
            return this.x = t.x + i.x,
            this.y = t.y + i.y,
            this.z = t.z + i.z,
            this
        },
        addSelf: function(t) {
            return this.x += t.x,
            this.y += t.y,
            this.z += t.z,
            this
        },
        addScalar: function(t) {
            return this.x += t,
            this.y += t,
            this.z += t,
            this
        },
        sub: function(t, i) {
            return this.x = t.x - i.x,
            this.y = t.y - i.y,
            this.z = t.z - i.z,
            this
        },
        subSelf: function(t) {
            return this.x -= t.x,
            this.y -= t.y,
            this.z -= t.z,
            this
        },
        cross: function(t, i) {
            return this.x = t.y * i.z - t.z * i.y,
            this.y = t.z * i.x - t.x * i.z,
            this.z = t.x * i.y - t.y * i.x,
            this
        },
        crossSelf: function(t) {
            var i = this.x
              , n = this.y
              , e = this.z;
            return this.x = n * t.z - e * t.y,
            this.y = e * t.x - i * t.z,
            this.z = i * t.y - n * t.x,
            this
        },
        multiplySelf: function(t) {
            return this.x *= t.x,
            this.y *= t.y,
            this.z *= t.z,
            this
        },
        multiplyScalar: function(t) {
            return this.x *= t,
            this.y *= t,
            this.z *= t,
            this
        },
        divideScalar: function(t) {
            return this.x /= t,
            this.y /= t,
            this.z /= t,
            this
        },
        dot: function(t) {
            return this.x * t.x + this.y * t.y + this.z * t.z
        },
        distanceTo: function(t) {
            return Math.sqrt(this.distanceToSquared(t))
        },
        distanceToSquared: function(t) {
            var i = this.x - t.x
              , n = this.y - t.y
              , e = this.z - t.z;
            return i * i + n * n + e * e
        },
        length: function() {
            return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z)
        },
        lengthSq: function() {
            return this.x * this.x + this.y * this.y + this.z * this.z
        },
        negate: function() {
            return this.x = -this.x,
            this.y = -this.y,
            this.z = -this.z,
            this
        },
        normalize: function() {
            return this.length() > 0 ? this.multiplyScalar(1 / this.length()) : this.multiplyScalar(0),
            this
        },
        setLength: function(t) {
            return this.normalize().multiplyScalar(t)
        },
        isZero: function() {
            var t = 1e-4;
            return Math.abs(this.x) < t && Math.abs(this.y) < t && Math.abs(this.z) < t
        },
        clone: function() {
            return new n.Vector3(this.x,this.y,this.z)
        },
        toString: function() {
            return "THREE.Vector3 ( " + this.x + ", " + this.y + ", " + this.z + " )"
        }
    },
    n.Vector4 = function(t, i, n, e) {
        this.x = t || 0,
        this.y = i || 0,
        this.z = n || 0,
        this.w = e || 1
    }
    ,
    n.Vector4.prototype = {
        set: function(t, i, n, e) {
            return this.x = t,
            this.y = i,
            this.z = n,
            this.w = e,
            this
        },
        copy: function(t) {
            return this.x = t.x,
            this.y = t.y,
            this.z = t.z,
            this.w = t.w,
            this
        },
        add: function(t, i) {
            return this.x = t.x + i.x,
            this.y = t.y + i.y,
            this.z = t.z + i.z,
            this.w = t.w + i.w,
            this
        },
        addSelf: function(t) {
            return this.x += t.x,
            this.y += t.y,
            this.z += t.z,
            this.w += t.w,
            this
        },
        sub: function(t, i) {
            return this.x = t.x - i.x,
            this.y = t.y - i.y,
            this.z = t.z - i.z,
            this.w = t.w - i.w,
            this
        },
        subSelf: function(t) {
            return this.x -= t.x,
            this.y -= t.y,
            this.z -= t.z,
            this.w -= t.w,
            this
        },
        clone: function() {
            return new n.Vector4(this.x,this.y,this.z,this.w)
        },
        toString: function() {
            return "THREE.Vector4 (" + this.x + ", " + this.y + ", " + this.z + ", " + this.w + ")"
        }
    },
    n.Rectangle = function() {
        function t() {
            r = e - i,
            s = o - n
        }
        var i, n, e, o, r, s, a = !0;
        this.getX = function() {
            return i
        }
        ,
        this.getY = function() {
            return n
        }
        ,
        this.getWidth = function() {
            return r
        }
        ,
        this.getHeight = function() {
            return s
        }
        ,
        this.getX1 = function() {
            return i
        }
        ,
        this.getY1 = function() {
            return n
        }
        ,
        this.getX2 = function() {
            return e
        }
        ,
        this.getY2 = function() {
            return o
        }
        ,
        this.set = function(r, s, h, l) {
            a = !1,
            i = r,
            n = s,
            e = h,
            o = l,
            t()
        }
        ,
        this.addPoint = function(r, s) {
            a ? (a = !1,
            i = r,
            n = s,
            e = r,
            o = s) : (i = Math.min(i, r),
            n = Math.min(n, s),
            e = Math.max(e, r),
            o = Math.max(o, s)),
            t()
        }
        ,
        this.addRectangle = function(r) {
            a ? (a = !1,
            i = r.getX1(),
            n = r.getY1(),
            e = r.getX2(),
            o = r.getY2()) : (i = Math.min(i, r.getX1()),
            n = Math.min(n, r.getY1()),
            e = Math.max(e, r.getX2()),
            o = Math.max(o, r.getY2())),
            t()
        }
        ,
        this.inflate = function(r) {
            i -= r,
            n -= r,
            e += r,
            o += r,
            t()
        }
        ,
        this.minSelf = function(r) {
            i = Math.max(i, r.getX1()),
            n = Math.max(n, r.getY1()),
            e = Math.min(e, r.getX2()),
            o = Math.min(o, r.getY2()),
            t()
        }
        ,
        this.instersects = function(t) {
            return Math.min(e, t.getX2()) - Math.max(i, t.getX1()) >= 0 && Math.min(o, t.getY2()) - Math.max(n, t.getY1()) >= 0
        }
        ,
        this.empty = function() {
            a = !0,
            i = 0,
            n = 0,
            e = 0,
            o = 0,
            t()
        }
        ,
        this.isEmpty = function() {
            return a
        }
        ,
        this.toString = function() {
            return "THREE.Rectangle (x1: " + i + ", y1: " + o + ", x2: " + e + ", y1: " + n + ", width: " + r + ", height: " + s + ")"
        }
    }
    ,
    n.Matrix3 = function() {
        this.m = []
    }
    ,
    n.Matrix3.prototype = {
        transpose: function() {
            var t;
            return t = this.m[1],
            this.m[1] = this.m[3],
            this.m[3] = t,
            t = this.m[2],
            this.m[2] = this.m[6],
            this.m[6] = t,
            t = this.m[5],
            this.m[5] = this.m[7],
            this.m[7] = t,
            this
        }
    },
    n.Matrix4 = function() {
        this._x = new n.Vector3,
        this._y = new n.Vector3,
        this._z = new n.Vector3
    }
    ,
    n.Matrix4.prototype = {
        n11: 1,
        n12: 0,
        n13: 0,
        n14: 0,
        n21: 0,
        n22: 1,
        n23: 0,
        n24: 0,
        n31: 0,
        n32: 0,
        n33: 1,
        n34: 0,
        n41: 0,
        n42: 0,
        n43: 0,
        n44: 1,
        identity: function() {
            this.n11 = 1,
            this.n12 = 0,
            this.n13 = 0,
            this.n14 = 0,
            this.n21 = 0,
            this.n22 = 1,
            this.n23 = 0,
            this.n24 = 0,
            this.n31 = 0,
            this.n32 = 0,
            this.n33 = 1,
            this.n34 = 0,
            this.n41 = 0,
            this.n42 = 0,
            this.n43 = 0,
            this.n44 = 1
        },
        copy: function(t) {
            this.n11 = t.n11,
            this.n12 = t.n12,
            this.n13 = t.n13,
            this.n14 = t.n14,
            this.n21 = t.n21,
            this.n22 = t.n22,
            this.n23 = t.n23,
            this.n24 = t.n24,
            this.n31 = t.n31,
            this.n32 = t.n32,
            this.n33 = t.n33,
            this.n34 = t.n34,
            this.n41 = t.n41,
            this.n42 = t.n42,
            this.n43 = t.n43,
            this.n44 = t.n44
        },
        lookAt: function(t, i, n) {
            var e = this._x
              , o = this._y
              , r = this._z;
            r.sub(t, i),
            r.normalize(),
            e.cross(n, r),
            e.normalize(),
            o.cross(r, e),
            o.normalize(),
            this.n11 = e.x,
            this.n12 = e.y,
            this.n13 = e.z,
            this.n14 = -e.dot(t),
            this.n21 = o.x,
            this.n22 = o.y,
            this.n23 = o.z,
            this.n24 = -o.dot(t),
            this.n31 = r.x,
            this.n32 = r.y,
            this.n33 = r.z,
            this.n34 = -r.dot(t),
            this.n41 = 0,
            this.n42 = 0,
            this.n43 = 0,
            this.n44 = 1
        },
        transform: function(t) {
            var i = t.x
              , n = t.y
              , e = t.z
              , o = t.w ? t.w : 1;
            return t.x = this.n11 * i + this.n12 * n + this.n13 * e + this.n14 * o,
            t.y = this.n21 * i + this.n22 * n + this.n23 * e + this.n24 * o,
            t.z = this.n31 * i + this.n32 * n + this.n33 * e + this.n34 * o,
            o = this.n41 * i + this.n42 * n + this.n43 * e + this.n44 * o,
            t.w ? t.w = o : (t.x = t.x / o,
            t.y = t.y / o,
            t.z = t.z / o),
            t
        },
        crossVector: function(t) {
            var i = new n.Vector4;
            return i.x = this.n11 * t.x + this.n12 * t.y + this.n13 * t.z + this.n14 * t.w,
            i.y = this.n21 * t.x + this.n22 * t.y + this.n23 * t.z + this.n24 * t.w,
            i.z = this.n31 * t.x + this.n32 * t.y + this.n33 * t.z + this.n34 * t.w,
            i.w = t.w ? this.n41 * t.x + this.n42 * t.y + this.n43 * t.z + this.n44 * t.w : 1,
            i
        },
        multiply: function(t, i) {
            this.n11 = t.n11 * i.n11 + t.n12 * i.n21 + t.n13 * i.n31 + t.n14 * i.n41,
            this.n12 = t.n11 * i.n12 + t.n12 * i.n22 + t.n13 * i.n32 + t.n14 * i.n42,
            this.n13 = t.n11 * i.n13 + t.n12 * i.n23 + t.n13 * i.n33 + t.n14 * i.n43,
            this.n14 = t.n11 * i.n14 + t.n12 * i.n24 + t.n13 * i.n34 + t.n14 * i.n44,
            this.n21 = t.n21 * i.n11 + t.n22 * i.n21 + t.n23 * i.n31 + t.n24 * i.n41,
            this.n22 = t.n21 * i.n12 + t.n22 * i.n22 + t.n23 * i.n32 + t.n24 * i.n42,
            this.n23 = t.n21 * i.n13 + t.n22 * i.n23 + t.n23 * i.n33 + t.n24 * i.n43,
            this.n24 = t.n21 * i.n14 + t.n22 * i.n24 + t.n23 * i.n34 + t.n24 * i.n44,
            this.n31 = t.n31 * i.n11 + t.n32 * i.n21 + t.n33 * i.n31 + t.n34 * i.n41,
            this.n32 = t.n31 * i.n12 + t.n32 * i.n22 + t.n33 * i.n32 + t.n34 * i.n42,
            this.n33 = t.n31 * i.n13 + t.n32 * i.n23 + t.n33 * i.n33 + t.n34 * i.n43,
            this.n34 = t.n31 * i.n14 + t.n32 * i.n24 + t.n33 * i.n34 + t.n34 * i.n44,
            this.n41 = t.n41 * i.n11 + t.n42 * i.n21 + t.n43 * i.n31 + t.n44 * i.n41,
            this.n42 = t.n41 * i.n12 + t.n42 * i.n22 + t.n43 * i.n32 + t.n44 * i.n42,
            this.n43 = t.n41 * i.n13 + t.n42 * i.n23 + t.n43 * i.n33 + t.n44 * i.n43,
            this.n44 = t.n41 * i.n14 + t.n42 * i.n24 + t.n43 * i.n34 + t.n44 * i.n44
        },
        multiplySelf: function(t) {
            var i = this.n11
              , n = this.n12
              , e = this.n13
              , o = this.n14
              , r = this.n21
              , s = this.n22
              , a = this.n23
              , h = this.n24
              , l = this.n31
              , c = this.n32
              , u = this.n33
              , f = this.n34
              , m = this.n41
              , p = this.n42
              , d = this.n43
              , x = this.n44;
            this.n11 = i * t.n11 + n * t.n21 + e * t.n31 + o * t.n41,
            this.n12 = i * t.n12 + n * t.n22 + e * t.n32 + o * t.n42,
            this.n13 = i * t.n13 + n * t.n23 + e * t.n33 + o * t.n43,
            this.n14 = i * t.n14 + n * t.n24 + e * t.n34 + o * t.n44,
            this.n21 = r * t.n11 + s * t.n21 + a * t.n31 + h * t.n41,
            this.n22 = r * t.n12 + s * t.n22 + a * t.n32 + h * t.n42,
            this.n23 = r * t.n13 + s * t.n23 + a * t.n33 + h * t.n43,
            this.n24 = r * t.n14 + s * t.n24 + a * t.n34 + h * t.n44,
            this.n31 = l * t.n11 + c * t.n21 + u * t.n31 + f * t.n41,
            this.n32 = l * t.n12 + c * t.n22 + u * t.n32 + f * t.n42,
            this.n33 = l * t.n13 + c * t.n23 + u * t.n33 + f * t.n43,
            this.n34 = l * t.n14 + c * t.n24 + u * t.n34 + f * t.n44,
            this.n41 = m * t.n11 + p * t.n21 + d * t.n31 + x * t.n41,
            this.n42 = m * t.n12 + p * t.n22 + d * t.n32 + x * t.n42,
            this.n43 = m * t.n13 + p * t.n23 + d * t.n33 + x * t.n43,
            this.n44 = m * t.n14 + p * t.n24 + d * t.n34 + x * t.n44
        },
        multiplyScalar: function(t) {
            this.n11 *= t,
            this.n12 *= t,
            this.n13 *= t,
            this.n14 *= t,
            this.n21 *= t,
            this.n22 *= t,
            this.n23 *= t,
            this.n24 *= t,
            this.n31 *= t,
            this.n32 *= t,
            this.n33 *= t,
            this.n34 *= t,
            this.n41 *= t,
            this.n42 *= t,
            this.n43 *= t,
            this.n44 *= t
        },
        determinant: function() {
            return this.n14 * this.n23 * this.n32 * this.n41 - this.n13 * this.n24 * this.n32 * this.n41 - this.n14 * this.n22 * this.n33 * this.n41 + this.n12 * this.n24 * this.n33 * this.n41 + this.n13 * this.n22 * this.n34 * this.n41 - this.n12 * this.n23 * this.n34 * this.n41 - this.n14 * this.n23 * this.n31 * this.n42 + this.n13 * this.n24 * this.n31 * this.n42 + this.n14 * this.n21 * this.n33 * this.n42 - this.n11 * this.n24 * this.n33 * this.n42 - this.n13 * this.n21 * this.n34 * this.n42 + this.n11 * this.n23 * this.n34 * this.n42 + this.n14 * this.n22 * this.n31 * this.n43 - this.n12 * this.n24 * this.n31 * this.n43 - this.n14 * this.n21 * this.n32 * this.n43 + this.n11 * this.n24 * this.n32 * this.n43 + this.n12 * this.n21 * this.n34 * this.n43 - this.n11 * this.n22 * this.n34 * this.n43 - this.n13 * this.n22 * this.n31 * this.n44 + this.n12 * this.n23 * this.n31 * this.n44 + this.n13 * this.n21 * this.n32 * this.n44 - this.n11 * this.n23 * this.n32 * this.n44 - this.n12 * this.n21 * this.n33 * this.n44 + this.n11 * this.n22 * this.n33 * this.n44
        },
        transpose: function() {
            function t(t, i, n) {
                var e = t[i];
                t[i] = t[n],
                t[n] = e
            }
            return t(this, "n21", "n12"),
            t(this, "n31", "n13"),
            t(this, "n32", "n23"),
            t(this, "n41", "n14"),
            t(this, "n42", "n24"),
            t(this, "n43", "n34"),
            this
        },
        clone: function() {
            var t = new n.Matrix4;
            return t.n11 = this.n11,
            t.n12 = this.n12,
            t.n13 = this.n13,
            t.n14 = this.n14,
            t.n21 = this.n21,
            t.n22 = this.n22,
            t.n23 = this.n23,
            t.n24 = this.n24,
            t.n31 = this.n31,
            t.n32 = this.n32,
            t.n33 = this.n33,
            t.n34 = this.n34,
            t.n41 = this.n41,
            t.n42 = this.n42,
            t.n43 = this.n43,
            t.n44 = this.n44,
            t
        },
        flatten: function() {
            return [this.n11, this.n21, this.n31, this.n41, this.n12, this.n22, this.n32, this.n42, this.n13, this.n23, this.n33, this.n43, this.n14, this.n24, this.n34, this.n44]
        },
        toString: function() {
            return "| " + this.n11 + " " + this.n12 + " " + this.n13 + " " + this.n14 + " |\n| " + this.n21 + " " + this.n22 + " " + this.n23 + " " + this.n24 + " |\n| " + this.n31 + " " + this.n32 + " " + this.n33 + " " + this.n34 + " |\n| " + this.n41 + " " + this.n42 + " " + this.n43 + " " + this.n44 + " |"
        }
    },
    n.Matrix4.translationMatrix = function(t, i, e) {
        var o = new n.Matrix4;
        return o.n14 = t,
        o.n24 = i,
        o.n34 = e,
        o
    }
    ,
    n.Matrix4.scaleMatrix = function(t, i, e) {
        var o = new n.Matrix4;
        return o.n11 = t,
        o.n22 = i,
        o.n33 = e,
        o
    }
    ,
    n.Matrix4.rotationXMatrix = function(t) {
        var i = new n.Matrix4;
        return i.n22 = i.n33 = Math.cos(t),
        i.n32 = Math.sin(t),
        i.n23 = -i.n32,
        i
    }
    ,
    n.Matrix4.rotationYMatrix = function(t) {
        var i = new n.Matrix4;
        return i.n11 = i.n33 = Math.cos(t),
        i.n13 = Math.sin(t),
        i.n31 = -i.n13,
        i
    }
    ,
    n.Matrix4.rotationZMatrix = function(t) {
        var i = new n.Matrix4;
        return i.n11 = i.n22 = Math.cos(t),
        i.n21 = Math.sin(t),
        i.n12 = -i.n21,
        i
    }
    ,
    n.Matrix4.rotationAxisAngleMatrix = function(t, i) {
        var e = new n.Matrix4
          , o = Math.cos(i)
          , r = Math.sin(i)
          , s = 1 - o
          , a = t.x
          , h = t.y
          , l = t.z;
        return e.n11 = s * a * a + o,
        e.n12 = s * a * h - r * l,
        e.n13 = s * a * l + r * h,
        e.n21 = s * a * h + r * l,
        e.n22 = s * h * h + o,
        e.n23 = s * h * l - r * a,
        e.n31 = s * a * l - r * h,
        e.n32 = s * h * l + r * a,
        e.n33 = s * l * l + o,
        e
    }
    ,
    n.Matrix4.makeInvert = function(t) {
        var i = new n.Matrix4;
        return i.n11 = t.n23 * t.n34 * t.n42 - t.n24 * t.n33 * t.n42 + t.n24 * t.n32 * t.n43 - t.n22 * t.n34 * t.n43 - t.n23 * t.n32 * t.n44 + t.n22 * t.n33 * t.n44,
        i.n12 = t.n14 * t.n33 * t.n42 - t.n13 * t.n34 * t.n42 - t.n14 * t.n32 * t.n43 + t.n12 * t.n34 * t.n43 + t.n13 * t.n32 * t.n44 - t.n12 * t.n33 * t.n44,
        i.n13 = t.n13 * t.n24 * t.n42 - t.n14 * t.n23 * t.n42 + t.n14 * t.n22 * t.n43 - t.n12 * t.n24 * t.n43 - t.n13 * t.n22 * t.n44 + t.n12 * t.n23 * t.n44,
        i.n14 = t.n14 * t.n23 * t.n32 - t.n13 * t.n24 * t.n32 - t.n14 * t.n22 * t.n33 + t.n12 * t.n24 * t.n33 + t.n13 * t.n22 * t.n34 - t.n12 * t.n23 * t.n34,
        i.n21 = t.n24 * t.n33 * t.n41 - t.n23 * t.n34 * t.n41 - t.n24 * t.n31 * t.n43 + t.n21 * t.n34 * t.n43 + t.n23 * t.n31 * t.n44 - t.n21 * t.n33 * t.n44,
        i.n22 = t.n13 * t.n34 * t.n41 - t.n14 * t.n33 * t.n41 + t.n14 * t.n31 * t.n43 - t.n11 * t.n34 * t.n43 - t.n13 * t.n31 * t.n44 + t.n11 * t.n33 * t.n44,
        i.n23 = t.n14 * t.n23 * t.n41 - t.n13 * t.n24 * t.n41 - t.n14 * t.n21 * t.n43 + t.n11 * t.n24 * t.n43 + t.n13 * t.n21 * t.n44 - t.n11 * t.n23 * t.n44,
        i.n24 = t.n13 * t.n24 * t.n31 - t.n14 * t.n23 * t.n31 + t.n14 * t.n21 * t.n33 - t.n11 * t.n24 * t.n33 - t.n13 * t.n21 * t.n34 + t.n11 * t.n23 * t.n34,
        i.n31 = t.n22 * t.n34 * t.n41 - t.n24 * t.n32 * t.n41 + t.n24 * t.n31 * t.n42 - t.n21 * t.n34 * t.n42 - t.n22 * t.n31 * t.n44 + t.n21 * t.n32 * t.n44,
        i.n32 = t.n14 * t.n32 * t.n41 - t.n12 * t.n34 * t.n41 - t.n14 * t.n31 * t.n42 + t.n11 * t.n34 * t.n42 + t.n12 * t.n31 * t.n44 - t.n11 * t.n32 * t.n44,
        i.n33 = t.n13 * t.n24 * t.n41 - t.n14 * t.n22 * t.n41 + t.n14 * t.n21 * t.n42 - t.n11 * t.n24 * t.n42 - t.n12 * t.n21 * t.n44 + t.n11 * t.n22 * t.n44,
        i.n34 = t.n14 * t.n22 * t.n31 - t.n12 * t.n24 * t.n31 - t.n14 * t.n21 * t.n32 + t.n11 * t.n24 * t.n32 + t.n12 * t.n21 * t.n34 - t.n11 * t.n22 * t.n34,
        i.n41 = t.n23 * t.n32 * t.n41 - t.n22 * t.n33 * t.n41 - t.n23 * t.n31 * t.n42 + t.n21 * t.n33 * t.n42 + t.n22 * t.n31 * t.n43 - t.n21 * t.n32 * t.n43,
        i.n42 = t.n12 * t.n33 * t.n41 - t.n13 * t.n32 * t.n41 + t.n13 * t.n31 * t.n42 - t.n11 * t.n33 * t.n42 - t.n12 * t.n31 * t.n43 + t.n11 * t.n32 * t.n43,
        i.n43 = t.n13 * t.n22 * t.n41 - t.n12 * t.n23 * t.n41 - t.n13 * t.n21 * t.n42 + t.n11 * t.n23 * t.n42 + t.n12 * t.n21 * t.n43 - t.n11 * t.n22 * t.n43,
        i.n44 = t.n12 * t.n23 * t.n31 - t.n13 * t.n22 * t.n31 + t.n13 * t.n21 * t.n32 - t.n11 * t.n23 * t.n32 - t.n12 * t.n21 * t.n33 + t.n11 * t.n22 * t.n33,
        i.multiplyScalar(1 / t.determinant()),
        i
    }
    ,
    n.Matrix4.makeInvert3x3 = function(t) {
        var i, e = t.flatten(), o = new n.Matrix3, r = e[10] * e[5] - e[6] * e[9], s = -e[10] * e[1] + e[2] * e[9], a = e[6] * e[1] - e[2] * e[5], h = -e[10] * e[4] + e[6] * e[8], l = e[10] * e[0] - e[2] * e[8], c = -e[6] * e[0] + e[2] * e[4], u = e[9] * e[4] - e[5] * e[8], f = -e[9] * e[0] + e[1] * e[8], m = e[5] * e[0] - e[1] * e[4], p = e[0] * r + e[1] * h + e[2] * u;
        if (0 == p)
            throw "matrix not invertible";
        return i = 1 / p,
        o.m[0] = i * r,
        o.m[1] = i * s,
        o.m[2] = i * a,
        o.m[3] = i * h,
        o.m[4] = i * l,
        o.m[5] = i * c,
        o.m[6] = i * u,
        o.m[7] = i * f,
        o.m[8] = i * m,
        o
    }
    ,
    n.Matrix4.makeFrustum = function(t, i, e, o, r, s) {
        var a, h, l, c, u, f, m;
        return a = new n.Matrix4,
        h = 2 * r / (i - t),
        l = 2 * r / (o - e),
        c = (i + t) / (i - t),
        u = (o + e) / (o - e),
        f = -(s + r) / (s - r),
        m = -2 * s * r / (s - r),
        a.n11 = h,
        a.n12 = 0,
        a.n13 = c,
        a.n14 = 0,
        a.n21 = 0,
        a.n22 = l,
        a.n23 = u,
        a.n24 = 0,
        a.n31 = 0,
        a.n32 = 0,
        a.n33 = f,
        a.n34 = m,
        a.n41 = 0,
        a.n42 = 0,
        a.n43 = -1,
        a.n44 = 0,
        a
    }
    ,
    n.Matrix4.makePerspective = function(t, i, e, o) {
        var r, s, a, h;
        return r = e * Math.tan(t * Math.PI / 360),
        s = -r,
        a = s * i,
        h = r * i,
        n.Matrix4.makeFrustum(a, h, s, r, e, o)
    }
    ,
    n.Matrix4.makeOrtho = function(t, i, e, o, r, s) {
        var a, h, l, c, u, f, m;
        return a = new n.Matrix4,
        u = i - t,
        f = o - e,
        m = s - r,
        h = (i + t) / u,
        l = (o + e) / f,
        c = (s + r) / m,
        a.n11 = 2 / u,
        a.n12 = 0,
        a.n13 = 0,
        a.n14 = -h,
        a.n21 = 0,
        a.n22 = 2 / f,
        a.n23 = 0,
        a.n24 = -l,
        a.n31 = 0,
        a.n32 = 0,
        a.n33 = -2 / m,
        a.n34 = -c,
        a.n41 = 0,
        a.n42 = 0,
        a.n43 = 0,
        a.n44 = 1,
        a
    }
    ,
    n.Vertex = function(t, i) {
        this.position = t || new n.Vector3,
        this.positionWorld = new n.Vector3,
        this.positionScreen = new n.Vector3,
        this.normal = i || new n.Vector3,
        this.normalWorld = new n.Vector3,
        this.normalScreen = new n.Vector3,
        this.__visible = !0
    }
    ,
    n.Vertex.prototype = {
        toString: function() {
            return "THREE.Vertex ( position: " + this.position + ", normal: " + this.normal + " )"
        }
    },
    n.Face3 = function(t, i, e, o, r) {
        this.a = t,
        this.b = i,
        this.c = e,
        this.centroid = new n.Vector3,
        this.normal = o instanceof n.Vector3 ? o : new n.Vector3,
        this.vertexNormals = o instanceof Array ? o : [],
        this.material = r instanceof Array ? r : [r]
    }
    ,
    n.Face3.prototype = {
        toString: function() {
            return "THREE.Face3 ( " + this.a + ", " + this.b + ", " + this.c + " )"
        }
    },
    n.Face4 = function(t, i, e, o, r, s) {
        this.a = t,
        this.b = i,
        this.c = e,
        this.d = o,
        this.centroid = new n.Vector3,
        this.normal = r instanceof n.Vector3 ? r : new n.Vector3,
        this.vertexNormals = r instanceof Array ? r : [],
        this.material = s instanceof Array ? s : [s]
    }
    ,
    n.Face4.prototype = {
        toString: function() {
            return "THREE.Face4 ( " + this.a + ", " + this.b + ", " + this.c + " " + this.d + " )"
        }
    },
    n.UV = function(t, i) {
        this.u = t || 0,
        this.v = i || 0
    }
    ,
    n.UV.prototype = {
        copy: function(t) {
            this.u = t.u,
            this.v = t.v
        },
        toString: function() {
            return "THREE.UV (" + this.u + ", " + this.v + ")"
        }
    },
    n.Geometry = function() {
        this.vertices = [],
        this.faces = [],
        this.uvs = []
    }
    ,
    n.Geometry.prototype = {
        computeCentroids: function() {
            var t, i, e;
            for (t = 0,
            i = this.faces.length; t < i; t++)
                e = this.faces[t],
                e.centroid.set(0, 0, 0),
                e instanceof n.Face3 ? (e.centroid.addSelf(this.vertices[e.a].position),
                e.centroid.addSelf(this.vertices[e.b].position),
                e.centroid.addSelf(this.vertices[e.c].position),
                e.centroid.divideScalar(3)) : e instanceof n.Face4 && (e.centroid.addSelf(this.vertices[e.a].position),
                e.centroid.addSelf(this.vertices[e.b].position),
                e.centroid.addSelf(this.vertices[e.c].position),
                e.centroid.addSelf(this.vertices[e.d].position),
                e.centroid.divideScalar(4))
        },
        computeNormals: function(t) {
            var i, e, o, r, s, a, h, l, c, u, f, m = new n.Vector3, p = new n.Vector3;
            for (o = 0,
            r = this.vertices.length; o < r; o++)
                s = this.vertices[o],
                s.normal.set(0, 0, 0);
            for (a = 0,
            h = this.faces.length; a < h; a++)
                if (l = this.faces[a],
                t && l.vertexNormals.length) {
                    for (m.set(0, 0, 0),
                    i = 0,
                    e = l.normal.length; i < e; i++)
                        m.addSelf(l.vertexNormals[i]);
                    m.divideScalar(3),
                    m.isZero() || m.normalize(),
                    l.normal.copy(m)
                } else
                    c = this.vertices[l.a],
                    u = this.vertices[l.b],
                    f = this.vertices[l.c],
                    m.sub(f.position, u.position),
                    p.sub(c.position, u.position),
                    m.crossSelf(p),
                    m.isZero() || m.normalize(),
                    l.normal.copy(m)
        },
        computeBoundingBox: function() {
            if (this.vertices.length > 0) {
                this.bbox = {
                    x: [this.vertices[0].position.x, this.vertices[0].position.x],
                    y: [this.vertices[0].position.y, this.vertices[0].position.y],
                    z: [this.vertices[0].position.z, this.vertices[0].position.z]
                };
                for (var t = 1, i = this.vertices.length; t < i; t++)
                    vertex = this.vertices[t],
                    vertex.position.x < this.bbox.x[0] ? this.bbox.x[0] = vertex.position.x : vertex.position.x > this.bbox.x[1] && (this.bbox.x[1] = vertex.position.x),
                    vertex.position.y < this.bbox.y[0] ? this.bbox.y[0] = vertex.position.y : vertex.position.y > this.bbox.y[1] && (this.bbox.y[1] = vertex.position.y),
                    vertex.position.z < this.bbox.z[0] ? this.bbox.z[0] = vertex.position.z : vertex.position.z > this.bbox.z[1] && (this.bbox.z[1] = vertex.position.z)
            }
        },
        toString: function() {
            return "THREE.Geometry ( vertices: " + this.vertices + ", faces: " + this.faces + " )"
        }
    },
    n.Camera = function(t, i, e, o) {
        this.fov = t,
        this.aspect = i,
        this.position = new n.Vector3(0,0,0),
        this.target = {
            position: new n.Vector3(0,0,0)
        },
        this.projectionMatrix = n.Matrix4.makePerspective(t, i, e, o),
        this.up = new n.Vector3(0,1,0),
        this.matrix = new n.Matrix4,
        this.autoUpdateMatrix = !0,
        this.updateMatrix = function() {
            this.matrix.lookAt(this.position, this.target.position, this.up)
        }
        ,
        this.toString = function() {
            return "THREE.Camera ( " + this.position + ", " + this.target.position + " )"
        }
    }
    ,
    n.Light = function(t) {
        this.color = new n.Color(255 << 24 | t)
    }
    ,
    n.AmbientLight = function(t) {
        n.Light.call(this, t)
    }
    ,
    n.AmbientLight.prototype = new n.Light,
    n.AmbientLight.prototype.constructor = n.AmbientLight,
    n.DirectionalLight = function(t, i) {
        n.Light.call(this, t),
        this.position = new n.Vector3(0,1,0),
        this.intensity = i || 1
    }
    ,
    n.DirectionalLight.prototype = new n.Light,
    n.DirectionalLight.prototype.constructor = n.DirectionalLight,
    n.PointLight = function(t, i) {
        n.Light.call(this, t),
        this.position = new n.Vector3(0,0,0),
        this.intensity = i || 1
    }
    ,
    n.DirectionalLight.prototype = new n.Light,
    n.DirectionalLight.prototype.constructor = n.PointLight,
    n.Object3D = function(t) {
        this.position = new n.Vector3,
        this.rotation = new n.Vector3,
        this.scale = new n.Vector3(1,1,1),
        this.matrix = new n.Matrix4,
        this.matrixTranslation = new n.Matrix4,
        this.matrixRotation = new n.Matrix4,
        this.matrixScale = new n.Matrix4,
        this.screen = new n.Vector3,
        this.autoUpdateMatrix = !0,
        this.updateMatrix = function() {
            this.matrixPosition = n.Matrix4.translationMatrix(this.position.x, this.position.y, this.position.z),
            this.matrixRotation = n.Matrix4.rotationXMatrix(this.rotation.x),
            this.matrixRotation.multiplySelf(n.Matrix4.rotationYMatrix(this.rotation.y)),
            this.matrixRotation.multiplySelf(n.Matrix4.rotationZMatrix(this.rotation.z)),
            this.matrixScale = n.Matrix4.scaleMatrix(this.scale.x, this.scale.y, this.scale.z),
            this.matrix.copy(this.matrixPosition),
            this.matrix.multiplySelf(this.matrixRotation),
            this.matrix.multiplySelf(this.matrixScale)
        }
    }
    ,
    n.Particle = function(t) {
        n.Object3D.call(this),
        this.material = t instanceof Array ? t : [t],
        this.autoUpdateMatrix = !1
    }
    ,
    n.Particle.prototype = new n.Object3D,
    n.Particle.prototype.constructor = n.Particle,
    n.Line = function(t, i) {
        n.Object3D.call(this),
        this.geometry = t,
        this.material = i instanceof Array ? i : [i]
    }
    ,
    n.Line.prototype = new n.Object3D,
    n.Line.prototype.constructor = n.Line,
    n.Mesh = function(t, i, e) {
        n.Object3D.call(this),
        this.geometry = t,
        this.material = i instanceof Array ? i : [i],
        this.flipSided = !1,
        this.doubleSided = !1,
        this.overdraw = !1,
        this.materialFaceGroup = {},
        this.sortFacesByMaterial(),
        e && this.normalizeUVs(),
        this.geometry.computeBoundingBox()
    }
    ,
    n.Mesh.prototype = new n.Object3D,
    n.Mesh.prototype.constructor = n.Mesh,
    n.Mesh.prototype.sortFacesByMaterial = function() {
        function t(t) {
            for (a = [],
            i = 0,
            n = t.length; i < n; i++)
                void 0 == t[i] ? a.push("undefined") : a.push(t[i].toString());
            return a.join("_")
        }
        var i, n, e, o, r, s, a;
        for (e = 0,
        o = this.geometry.faces.length; e < o; e++)
            r = this.geometry.faces[e],
            s = r.material,
            hash = t(s),
            void 0 == this.materialFaceGroup[hash] && (this.materialFaceGroup[hash] = {
                faces: [],
                material: s
            }),
            this.materialFaceGroup[hash].faces.push(e)
    }
    ,
    n.Mesh.prototype.normalizeUVs = function() {
        var t, i, n, e, o;
        for (t = 0,
        i = this.geometry.uvs.length; t < i; t++)
            for (o = this.geometry.uvs[t],
            n = 0,
            e = o.length; n < e; n++)
                1 != o[n].u && (o[n].u = o[n].u - Math.floor(o[n].u)),
                1 != o[n].v && (o[n].v = o[n].v - Math.floor(o[n].v))
    }
    ,
    n.LineColorMaterial = function(t, i, e) {
        this.lineWidth = e || 1,
        this.color = new n.Color((i >= 0 ? 255 * i << 24 : 4278190080) | t)
    }
    ,
    n.LineColorMaterial.prototype = {
        toString: function() {
            return "THREE.LineColorMaterial ( color: " + this.color + ", lineWidth: " + this.lineWidth + " )"
        }
    },
    n.MeshPhongMaterial = function(t, i, e, o, r) {
        this.ambient = new n.Color((r >= 0 ? 255 * r << 24 : 4278190080) | t),
        this.diffuse = new n.Color((r >= 0 ? 255 * r << 24 : 4278190080) | i),
        this.specular = new n.Color((r >= 0 ? 255 * r << 24 : 4278190080) | e),
        this.shininess = o,
        this.opacity = r,
        this.toString = function() {
            return "THREE.MeshPhongMaterial ( <br/>ambient: " + this.ambient + ", <br/>diffuse: " + this.diffuse + ", <br/>specular: " + this.specular + ", <br/>shininess: " + this.shininess + ", <br/>opacity: " + this.opacity + ")"
        }
    }
    ,
    n.MeshBitmapMaterial = function(t, i) {
        this.bitmap = t,
        this.mode = i || n.MeshBitmapMaterialMode.UVMAPPING,
        this.id = n.MeshBitmapMaterialCounter.value++,
        this.toString = function() {
            return "THREE.MeshBitmapMaterial ( bitmap: " + this.bitmap + ", mode: " + this.mode + ", id: " + this.id + " )"
        }
    }
    ,
    n.MeshBitmapMaterialCounter = {
        value: 0
    },
    n.MeshBitmapMaterialMode = {
        UVMAPPING: 0
    },
    n.MeshColorFillMaterial = function(t, i) {
        this.color = new n.Color((i >= 0 ? 255 * i << 24 : 4278190080) | t),
        this.toString = function() {
            return "THREE.MeshColorFillMaterial ( color: " + this.color + " )"
        }
    }
    ,
    n.MeshColorStrokeMaterial = function(t, i, e) {
        this.lineWidth = e || 1,
        this.color = new n.Color((i >= 0 ? 255 * i << 24 : 4278190080) | t),
        this.toString = function() {
            return "THREE.MeshColorStrokeMaterial ( lineWidth: " + this.lineWidth + ", color: " + this.color + " )"
        }
    }
    ,
    n.MeshFaceMaterial = function() {
        this.toString = function() {
            return "THREE.MeshFaceMaterial"
        }
    }
    ,
    n.ParticleBitmapMaterial = function(t) {
        this.bitmap = t,
        this.offset = new n.Vector2,
        this.toString = function() {
            return "THREE.ParticleBitmapMaterial ( bitmap: " + this.bitmap + " )"
        }
    }
    ,
    n.ParticleCircleMaterial = function(t, i) {
        this.color = new n.Color((i >= 0 ? 255 * i << 24 : 4278190080) | t),
        this.toString = function() {
            return "THREE.ParticleCircleMaterial ( color: " + this.color + " )"
        }
    }
    ,
    n.ParticleDOMMaterial = function(t) {
        this.domElement = t,
        this.toString = function() {
            return "THREE.ParticleDOMMaterial ( domElement: " + this.domElement + " )"
        }
    }
    ,
    n.Scene = function() {
        this.objects = [],
        this.lights = [],
        this.addObject = function(t) {
            this.objects.push(t)
        }
        ,
        this.removeObject = function(t) {
            for (var i = 0, n = this.objects.length; i < n; i++)
                if (t == this.objects[i])
                    return void this.objects.splice(i, 1)
        }
        ,
        this.addLight = function(t) {
            this.lights.push(t)
        }
        ,
        this.removeLight = function(t) {
            for (var i = 0, n = this.lights.length; i < n; i++)
                if (t == this.lights[i])
                    return void this.lights.splice(i, 1)
        }
        ,
        this.add = function(t) {
            this.addObject(t)
        }
        ,
        this.toString = function() {
            return "THREE.Scene ( " + this.objects + " )"
        }
    }
    ,
    n.Projector = function() {
        var t, i, e, o, r, s, a, h, l = null, c = [], u = [], f = [], m = [], p = new n.Vector4, d = new n.Matrix4, x = new n.Matrix4;
        this.projectScene = function(g, v) {
            var y, b, M, w, S, _, z, R, L, A, E, P, C, B, V, T, F, D, G;
            for (l = [],
            i = 0,
            o = 0,
            s = 0,
            h = 0,
            v.autoUpdateMatrix && v.updateMatrix(),
            d.multiply(v.projectionMatrix, v.matrix),
            z = g.objects,
            y = 0,
            b = z.length; y < b; y++)
                if (R = z[y],
                L = R.matrix,
                R.autoUpdateMatrix && R.updateMatrix(),
                R instanceof n.Mesh) {
                    for (x.multiply(d, L),
                    A = R.geometry.vertices,
                    M = 0,
                    w = A.length; M < w; M++)
                        E = A[M],
                        P = E.positionScreen,
                        P.copy(E.position),
                        x.transform(P),
                        E.__visible = P.z > 0 && P.z < 1;
                    for (B = R.geometry.faces,
                    S = 0,
                    _ = B.length; S < _; S++)
                        V = B[S],
                        V instanceof n.Face3 ? (T = A[V.a],
                        F = A[V.b],
                        D = A[V.c],
                        T.__visible && F.__visible && D.__visible && (R.doubleSided || R.flipSided != (D.positionScreen.x - T.positionScreen.x) * (F.positionScreen.y - T.positionScreen.y) - (D.positionScreen.y - T.positionScreen.y) * (F.positionScreen.x - T.positionScreen.x) < 0) && (t = c[i] = c[i] || new n.RenderableFace3,
                        t.v1.copy(T.positionScreen),
                        t.v2.copy(F.positionScreen),
                        t.v3.copy(D.positionScreen),
                        t.centroidWorld.copy(V.centroid),
                        R.matrix.transform(t.centroidWorld),
                        t.normalWorld.copy(V.normal),
                        R.matrixRotation.transform(t.normalWorld),
                        t.z = Math.max(T.positionScreen.z, Math.max(F.positionScreen.z, D.positionScreen.z)),
                        t.meshMaterial = R.material,
                        t.faceMaterial = V.material,
                        t.overdraw = R.overdraw,
                        t.uvs = R.geometry.uvs[S],
                        t.color = V.color,
                        l.push(t),
                        i++)) : V instanceof n.Face4 && (T = A[V.a],
                        F = A[V.b],
                        D = A[V.c],
                        G = A[V.d],
                        T.__visible && F.__visible && D.__visible && G.__visible && (R.doubleSided || R.flipSided != ((G.positionScreen.x - T.positionScreen.x) * (F.positionScreen.y - T.positionScreen.y) - (G.positionScreen.y - T.positionScreen.y) * (F.positionScreen.x - T.positionScreen.x) < 0 || (F.positionScreen.x - D.positionScreen.x) * (G.positionScreen.y - D.positionScreen.y) - (F.positionScreen.y - D.positionScreen.y) * (G.positionScreen.x - D.positionScreen.x) < 0)) && (e = u[o] = u[o] || new n.RenderableFace4,
                        e.v1.copy(T.positionScreen),
                        e.v2.copy(F.positionScreen),
                        e.v3.copy(D.positionScreen),
                        e.v4.copy(G.positionScreen),
                        e.centroidWorld.copy(V.centroid),
                        R.matrix.transform(e.centroidWorld),
                        e.normalWorld.copy(V.normal),
                        R.matrixRotation.transform(e.normalWorld),
                        e.z = Math.max(T.positionScreen.z, Math.max(F.positionScreen.z, Math.max(D.positionScreen.z, G.positionScreen.z))),
                        e.meshMaterial = R.material,
                        e.faceMaterial = V.material,
                        e.overdraw = R.overdraw,
                        e.uvs = R.geometry.uvs[S],
                        e.color = V.color,
                        l.push(e),
                        o++))
                } else if (R instanceof n.Line)
                    for (x.multiply(d, L),
                    A = R.geometry.vertices,
                    M = 0,
                    w = A.length; M < w; M++)
                        E = A[M],
                        P = E.positionScreen,
                        P.copy(E.position),
                        x.transform(P),
                        E.__visible = P.z > 0 && P.z < 1,
                        M > 0 && (C = R.geometry.vertices[M - 1],
                        E.__visible && C.__visible && (r = f[s] = f[s] || new n.RenderableLine,
                        r.v1.copy(E.positionScreen),
                        r.v2.copy(C.positionScreen),
                        r.z = Math.max(E.positionScreen.z, C.positionScreen.z),
                        r.material = R.material,
                        l.push(r),
                        s++));
                else
                    R instanceof n.Particle && (p.set(R.position.x, R.position.y, R.position.z, 1),
                    v.matrix.transform(p),
                    v.projectionMatrix.transform(p),
                    R.screen.set(p.x / p.w, p.y / p.w, p.z / p.w),
                    R.screen.z > 0 && R.screen.z < 1 && (a = m[h] = m[h] || new n.RenderableParticle,
                    a.x = R.screen.x,
                    a.y = R.screen.y,
                    a.z = R.screen.z,
                    a.rotation = R.rotation.z,
                    a.scale.x = R.scale.x * Math.abs(p.x / p.w - (p.x + v.projectionMatrix.n11) / (p.w + v.projectionMatrix.n14)),
                    a.scale.y = R.scale.y * Math.abs(p.y / p.w - (p.y + v.projectionMatrix.n22) / (p.w + v.projectionMatrix.n24)),
                    a.material = R.material,
                    a.color = R.color,
                    l.push(a),
                    h++));
            return l.sort(function(t, i) {
                return i.z - t.z
            }),
            l
        }
    }
    ,
    n.DOMRenderer = function() {
        n.Renderer.call(this);
        var t, i, e, o, r = null, s = new n.Projector, a = document.createElement("div");
        this.domElement = a,
        this.setSize = function(n, r) {
            t = n,
            i = r,
            e = t / 2,
            o = i / 2
        }
        ,
        this.render = function(t, i) {
            var a, h, l, c, u, f, m, p, d;
            for (r = s.projectScene(t, i),
            a = 0,
            h = r.length; a < h; a++)
                if (u = r[a],
                u instanceof n.RenderableParticle)
                    for (p = u.x * e + e,
                    d = u.y * o + o,
                    l = 0,
                    c = u.material.length; l < c; l++)
                        f = u.material[l],
                        f instanceof n.ParticleDOMMaterial && (m = f.domElement,
                        m.style.left = p + "px",
                        m.style.top = d + "px")
        }
    }
    ,
    n.CanvasRenderer = function() {
        function t(t, i) {
            var e, o, r;
            for (i.setRGBA(1, 1, 1, 1),
            e = 0,
            o = t.lights.length; e < o; e++)
                r = t.lights[e],
                r instanceof n.AmbientLight && (i.r *= r.color.r,
                i.g *= r.color.g,
                i.b *= r.color.b)
        }
        function i(t, i, e) {
            var o, r, s;
            for (o = 0,
            r = t.lights.length; o < r; o++)
                s = t.lights[o],
                s instanceof n.DirectionalLight ? (e.r += s.color.r,
                e.g += s.color.g,
                e.b += s.color.b) : s instanceof n.PointLight && (e.r += s.color.r,
                e.g += s.color.g,
                e.b += s.color.b)
        }
        function e(t, i, e) {
            var o, r, s, a;
            for (o = 0,
            r = t.lights.length; o < r; o++)
                s = t.lights[o],
                s instanceof n.DirectionalLight ? (a = i.normalWorld.dot(s.position) * s.intensity,
                a > 0 && (e.r += s.color.r * a,
                e.g += s.color.g * a,
                e.b += s.color.b * a)) : s instanceof n.PointLight && (L.sub(s.position, i.centroidWorld),
                L.normalize(),
                a = i.normalWorld.dot(L) * s.intensity,
                a > 0 && (e.r += s.color.r * a,
                e.g += s.color.g * a,
                e.b += s.color.b * a))
        }
        function o(t, e, o, r, s) {
            var a, h, l, c, u, p, d, x, y;
            if (r instanceof n.ParticleCircleMaterial) {
                if (M ? (S.copyRGB(_),
                i(s, o, S),
                w.copyRGBA(r.color),
                w.multiplySelfRGB(S),
                w.updateStyleString()) : w = r.color,
                a = o.scale.x * f,
                h = o.scale.y * m,
                b.set(t - a, e - h, t + a, e + h),
                !v.instersects(b))
                    return;
                g.save(),
                g.translate(t, e),
                g.rotate(-o.rotation),
                g.scale(a, h),
                g.beginPath(),
                g.arc(0, 0, 1, 0, z, !0),
                g.closePath(),
                g.fillStyle = w.__styleString,
                g.fill(),
                g.restore()
            } else if (r instanceof n.ParticleBitmapMaterial) {
                if (d = r.bitmap,
                x = d.width / 2,
                y = d.height / 2,
                l = o.scale.x * f,
                c = o.scale.y * m,
                a = l * x,
                h = c * y,
                u = r.offset.x * l,
                p = r.offset.y * c,
                b.set(t + u - a, e + p - h, t + u + a, e + p + h),
                !v.instersects(b))
                    return;
                g.save(),
                g.translate(t, e),
                g.rotate(-o.rotation),
                g.scale(l, -c),
                g.translate(-x + r.offset.x, -y - r.offset.y),
                g.drawImage(d, 0, 0),
                g.restore()
            }
        }
        function r(t, e, o, r, s, a, h) {
            a instanceof n.LineColorMaterial && (M ? (S.copyRGB(_),
            i(h, s, S),
            w.copyRGBA(a.color),
            w.multiplySelfRGB(S),
            w.updateStyleString()) : w = a.color,
            g.lineWidth = a.lineWidth,
            g.lineJoin = "round",
            g.lineCap = "round",
            g.strokeStyle = w.__styleString,
            g.stroke(),
            b.inflate(g.lineWidth))
        }
        function s(t, i, o, r, s, a, l, c, u) {
            var f, m, p;
            c instanceof n.MeshColorFillMaterial ? (M ? (S.copyRGB(_),
            e(u, l, S),
            w.copyRGBA(c.color),
            w.multiplySelfRGB(S),
            w.updateStyleString()) : w = c.color,
            g.beginPath(),
            g.moveTo(t, i),
            g.lineTo(o, r),
            g.lineTo(s, a),
            g.lineTo(t, i),
            g.closePath(),
            g.fillStyle = w.__styleString,
            g.fill()) : c instanceof n.MeshColorStrokeMaterial ? (M ? (S.copyRGB(_),
            e(u, l, S),
            w.copyRGBA(c.color),
            w.multiplySelfRGB(S),
            w.updateStyleString()) : w = c.color,
            g.beginPath(),
            g.moveTo(t, i),
            g.lineTo(o, r),
            g.lineTo(s, a),
            g.lineTo(t, i),
            g.closePath(),
            g.lineWidth = c.lineWidth,
            g.lineJoin = "round",
            g.lineCap = "round",
            g.strokeStyle = w.__styleString,
            g.stroke(),
            b.inflate(g.lineWidth)) : c instanceof n.MeshBitmapMaterial && (f = c.bitmap,
            m = f.width - 1,
            p = f.height - 1,
            A.copy(l.uvs[0]),
            E.copy(l.uvs[1]),
            P.copy(l.uvs[2]),
            A.u *= m,
            A.v *= p,
            E.u *= m,
            E.v *= p,
            P.u *= m,
            P.v *= p,
            h(f, t, i, o, r, s, a, A.u, A.v, E.u, E.v, P.u, P.v))
        }
        function a(t, i, o, r, s, a, l, c, u, f, m, p, d, x, v) {
            var y, z, R;
            x instanceof n.MeshColorFillMaterial ? (M ? (S.copyRGB(_),
            e(v, d, S),
            w.copyRGBA(x.color),
            w.multiplySelfRGB(S),
            w.updateStyleString()) : w = x.color,
            g.beginPath(),
            g.moveTo(t, i),
            g.lineTo(o, r),
            g.lineTo(s, a),
            g.lineTo(l, c),
            g.lineTo(t, i),
            g.closePath(),
            g.fillStyle = w.__styleString,
            g.fill()) : x instanceof n.MeshColorStrokeMaterial ? (M ? (S.copyRGB(_),
            e(v, d, S),
            w.copyRGBA(x.color),
            w.multiplySelfRGB(S),
            w.updateStyleString()) : w = x.color,
            g.beginPath(),
            g.moveTo(t, i),
            g.lineTo(o, r),
            g.lineTo(s, a),
            g.lineTo(l, c),
            g.lineTo(t, i),
            g.closePath(),
            g.lineWidth = x.lineWidth,
            g.lineJoin = "round",
            g.lineCap = "round",
            g.strokeStyle = w.__styleString,
            g.stroke(),
            b.inflate(g.lineWidth)) : x instanceof n.MeshBitmapMaterial && (y = x.bitmap,
            z = y.width - 1,
            R = y.height - 1,
            A.copy(d.uvs[0]),
            E.copy(d.uvs[1]),
            P.copy(d.uvs[2]),
            C.copy(d.uvs[3]),
            A.u *= z,
            A.v *= R,
            E.u *= z,
            E.v *= R,
            P.u *= z,
            P.v *= R,
            C.u *= z,
            C.v *= R,
            h(y, t, i, o, r, l, c, A.u, A.v, E.u, E.v, C.u, C.v),
            h(y, u, f, s, a, m, p, E.u, E.v, P.u, P.v, C.u, C.v))
        }
        function h(t, i, n, e, o, r, s, a, h, l, c, u, f) {
            var m, p, d, x, v, y, b;
            g.beginPath(),
            g.moveTo(i, n),
            g.lineTo(e, o),
            g.lineTo(r, s),
            g.lineTo(i, n),
            g.closePath(),
            g.save(),
            g.clip(),
            m = a * (f - c) - l * f + u * c + (l - u) * h,
            p = -(h * (r - e) - c * r + f * e + (c - f) * i) / m,
            d = (c * s + h * (o - s) - f * o + (f - c) * n) / m,
            x = (a * (r - e) - l * r + u * e + (l - u) * i) / m,
            v = -(l * s + a * (o - s) - u * o + (u - l) * n) / m,
            y = (a * (f * e - c * r) + h * (l * r - u * e) + (u * c - l * f) * i) / m,
            b = (a * (f * o - c * s) + h * (l * s - u * o) + (u * c - l * f) * n) / m,
            g.transform(p, d, x, v, y, b),
            g.drawImage(t, 0, 0),
            g.restore()
        }
        function l(t, i) {
            R.sub(i, t),
            R.unit(),
            R.multiplyScalar(.75),
            i.addSelf(R),
            t.subSelf(R)
        }
        var c, u, f, m, p = null, d = new n.Projector, x = document.createElement("canvas"), g = x.getContext("2d"), v = new n.Rectangle, y = new n.Rectangle, b = new n.Rectangle, M = !1, w = new n.Color(4294967295), S = new n.Color(4294967295), _ = new n.Color(4294967295), z = 2 * Math.PI, R = new n.Vector2, L = new n.Vector3, A = new n.UV, E = new n.UV, P = new n.UV, C = new n.UV, B = new n.Vector2, V = new n.Vector2;
        this.domElement = x,
        this.autoClear = !0,
        this.setSize = function(t, i) {
            c = t,
            u = i,
            f = c / 2,
            m = u / 2,
            x.width = c,
            x.height = u,
            v.set(-f, -m, f, m)
        }
        ,
        this.clear = function() {
            y.isEmpty() || (y.inflate(1),
            y.minSelf(v),
            g.setTransform(1, 0, 0, -1, f, m),
            g.clearRect(y.getX(), y.getY(), y.getWidth(), y.getHeight()),
            y.empty())
        }
        ,
        this.render = function(i, e) {
            var h, c, u, x, w, S, z, R, L, A, E, P, C, T, F, D, G, U, W, j;
            for (this.autoClear && this.clear(),
            p = d.projectScene(i, e),
            g.setTransform(1, 0, 0, -1, f, m),
            M = i.lights.length > 0,
            M && t(i, _),
            h = 0,
            c = p.length; h < c; h++) {
                if (u = p[h],
                b.empty(),
                u instanceof n.RenderableParticle)
                    for (L = u.x * f,
                    A = u.y * m,
                    x = 0,
                    w = u.material.length; x < w; x++)
                        R = u.material[x],
                        o(L, A, u, R, i);
                else if (u instanceof n.RenderableLine) {
                    if (L = u.v1.x * f,
                    A = u.v1.y * m,
                    E = u.v2.x * f,
                    P = u.v2.y * m,
                    b.addPoint(L, A),
                    b.addPoint(E, P),
                    !v.instersects(b))
                        continue;
                    for (g.beginPath(),
                    g.moveTo(L, A),
                    g.lineTo(E, P),
                    g.closePath(),
                    x = 0,
                    w = u.material.length; x < w; x++)
                        R = u.material[x],
                        r(L, A, E, P, u, R, i)
                } else if (u instanceof n.RenderableFace3) {
                    if (u.v1.x *= f,
                    u.v1.y *= m,
                    u.v2.x *= f,
                    u.v2.y *= m,
                    u.v3.x *= f,
                    u.v3.y *= m,
                    u.overdraw && (l(u.v1, u.v2),
                    l(u.v2, u.v3),
                    l(u.v3, u.v1)),
                    L = u.v1.x,
                    A = u.v1.y,
                    E = u.v2.x,
                    P = u.v2.y,
                    C = u.v3.x,
                    T = u.v3.y,
                    b.addPoint(L, A),
                    b.addPoint(E, P),
                    b.addPoint(C, T),
                    !v.instersects(b))
                        continue;
                    for (x = 0,
                    w = u.meshMaterial.length; x < w; )
                        if (R = u.meshMaterial[x++],
                        R instanceof n.MeshFaceMaterial)
                            for (S = 0,
                            z = u.faceMaterial.length; S < z; )
                                R = u.faceMaterial[S++],
                                s(L, A, E, P, C, T, u, R, i);
                        else
                            s(L, A, E, P, C, T, u, R, i)
                } else if (u instanceof n.RenderableFace4) {
                    if (u.v1.x *= f,
                    u.v1.y *= m,
                    u.v2.x *= f,
                    u.v2.y *= m,
                    u.v3.x *= f,
                    u.v3.y *= m,
                    u.v4.x *= f,
                    u.v4.y *= m,
                    B.copy(u.v2),
                    V.copy(u.v4),
                    u.overdraw && (l(u.v1, u.v2),
                    l(u.v2, u.v4),
                    l(u.v4, u.v1)),
                    L = u.v1.x,
                    A = u.v1.y,
                    E = u.v2.x,
                    P = u.v2.y,
                    F = u.v4.x,
                    D = u.v4.y,
                    u.overdraw && (l(u.v3, B),
                    l(u.v3, V)),
                    C = u.v3.x,
                    T = u.v3.y,
                    G = B.x,
                    U = B.y,
                    W = V.x,
                    j = V.y,
                    b.addPoint(L, A),
                    b.addPoint(E, P),
                    b.addPoint(C, T),
                    b.addPoint(F, D),
                    !v.instersects(b))
                        continue;
                    for (x = 0,
                    w = u.meshMaterial.length; x < w; )
                        if (R = u.meshMaterial[x++],
                        R instanceof n.MeshFaceMaterial)
                            for (S = 0,
                            z = u.faceMaterial.length; S < z; )
                                R = u.faceMaterial[S++],
                                a(L, A, E, P, C, T, F, D, G, U, W, j, u, R, i);
                        else
                            a(L, A, E, P, C, T, F, D, G, U, W, j, u, R, i)
                }
                y.addRectangle(b)
            }
            g.setTransform(1, 0, 0, 1, 0, 0)
        }
    }
    ,
    n.SVGRenderer = function() {
        function t(t, i) {
            var e, o, r;
            for (i.setRGBA(1, 1, 1, 1),
            e = 0,
            o = t.lights.length; e < o; e++)
                r = t.lights[e],
                r instanceof n.AmbientLight && (i.r *= r.color.r,
                i.g *= r.color.g,
                i.b *= r.color.b)
        }
        function i(t, i, e) {
            var o, r, s;
            for (o = 0,
            r = t.lights.length; o < r; o++)
                s = t.lights[o],
                s instanceof n.DirectionalLight ? (e.r += s.color.r,
                e.g += s.color.g,
                e.b += s.color.b) : s instanceof n.PointLight && (e.r += s.color.r,
                e.g += s.color.g,
                e.b += s.color.b)
        }
        function e(t, i, e) {
            var o, r, s, a;
            for (o = 0,
            r = t.lights.length; o < r; o++)
                s = t.lights[o],
                s instanceof n.DirectionalLight ? (a = i.normalWorld.dot(s.position) * s.intensity,
                a > 0 && (e.r += s.color.r * a,
                e.g += s.color.g * a,
                e.b += s.color.b * a)) : s instanceof n.PointLight && (z.sub(s.position, i.centroidWorld),
                z.normalize(),
                a = i.normalWorld.dot(z) * s.intensity,
                a > 0 && (e.r += s.color.r * a,
                e.g += s.color.g * a,
                e.b += s.color.b * a))
        }
        function o(t, e, o, r, s) {
            m = h(d++),
            m.setAttribute("cx", t),
            m.setAttribute("cy", e),
            m.setAttribute("r", o.scale.x * u),
            r instanceof n.ParticleCircleMaterial && (M ? (S.copyRGB(_),
            i(s, o, S),
            w.copyRGBA(r.color),
            w.multiplySelfRGB(S),
            w.updateStyleString()) : w = r.color,
            m.setAttribute("style", "fill: " + w.__styleString)),
            v.appendChild(m)
        }
        function r(t, i, o, r, s, h, l, c, u) {
            m = a(p++),
            m.setAttribute("d", "M " + t + " " + i + " L " + o + " " + r + " L " + s + "," + h + "z"),
            c instanceof n.MeshColorFillMaterial ? (M ? (S.copyRGB(_),
            e(u, l, S),
            w.copyRGBA(c.color),
            w.multiplySelfRGB(S),
            w.updateStyleString()) : w = c.color,
            m.setAttribute("style", "fill: " + w.__styleString)) : c instanceof n.MeshColorStrokeMaterial && (M ? (S.copyRGB(_),
            e(u, l, S),
            w.copyRGBA(c.color),
            w.multiplySelfRGB(S),
            w.updateStyleString()) : w = c.color,
            m.setAttribute("style", "fill: none; stroke: " + w.__styleString + "; stroke-width: " + c.lineWidth + "; stroke-linecap: round; stroke-linejoin: round")),
            v.appendChild(m)
        }
        function s(t, i, o, r, s, h, l, c, u, f, d) {
            m = a(p++),
            m.setAttribute("d", "M " + t + " " + i + " L " + o + " " + r + " L " + s + "," + h + " L " + l + "," + c + "z"),
            f instanceof n.MeshColorFillMaterial ? (M ? (S.copyRGB(_),
            e(d, u, S),
            w.copyRGBA(f.color),
            w.multiplySelfRGB(S),
            w.updateStyleString()) : w = f.color,
            m.setAttribute("style", "fill: " + w.__styleString)) : f instanceof n.MeshColorStrokeMaterial && (M ? (S.copyRGB(_),
            e(d, u, S),
            w.copyRGBA(f.color),
            w.multiplySelfRGB(S),
            w.updateStyleString()) : w = f.color,
            m.setAttribute("style", "fill: none; stroke: " + w.__styleString + "; stroke-width: " + f.lineWidth + "; stroke-linecap: round; stroke-linejoin: round")),
            v.appendChild(m)
        }
        function a(t) {
            return null == R[t] ? (R[t] = document.createElementNS("http://www.w3.org/2000/svg", "path"),
            0 == A && R[t].setAttribute("shape-rendering", "crispEdges"),
            R[t]) : R[t]
        }
        function h(t) {
            return null == L[t] ? (L[t] = document.createElementNS("http://www.w3.org/2000/svg", "circle"),
            0 == A && L[t].setAttribute("shape-rendering", "crispEdges"),
            L[t]) : L[t]
        }
        var l, c, u, f, m, p, d, x = null, g = new n.Projector, v = document.createElementNS("http://www.w3.org/2000/svg", "svg"), y = new n.Rectangle, b = new n.Rectangle, M = !1, w = new n.Color(4294967295), S = new n.Color(4294967295), _ = new n.Color(4294967295), z = new n.Vector3, R = [], L = [], A = 1;
        this.domElement = v,
        this.autoClear = !0,
        this.setQuality = function(t) {
            switch (t) {
            case "high":
                A = 1;
                break;
            case "low":
                A = 0
            }
        }
        ,
        this.setSize = function(t, i) {
            l = t,
            c = i,
            u = l / 2,
            f = c / 2,
            v.setAttribute("viewBox", -u + " " + -f + " " + l + " " + c),
            v.setAttribute("width", l),
            v.setAttribute("height", c),
            y.set(-u, -f, u, f)
        }
        ,
        this.clear = function() {
            for (; v.childNodes.length > 0; )
                v.removeChild(v.childNodes[0])
        }
        ,
        this.render = function(i, e) {
            var a, h, l, c, m, v, w, S, z, R, L, A, E, P, C, B;
            for (this.autoClear && this.clear(),
            x = g.projectScene(i, e),
            p = 0,
            d = 0,
            M = i.lights.length > 0,
            M && t(i, _),
            a = 0,
            h = x.length; a < h; a++)
                if (w = x[a],
                b.empty(),
                w instanceof n.RenderableParticle)
                    for (z = w.x * u,
                    R = w.y * -f,
                    l = 0,
                    c = w.material.length; l < c; l++)
                        S = w.material[l],
                        o(z, R, w, S, i);
                else if (w instanceof n.RenderableFace3) {
                    if (z = w.v1.x * u,
                    R = w.v1.y * -f,
                    L = w.v2.x * u,
                    A = w.v2.y * -f,
                    E = w.v3.x * u,
                    P = w.v3.y * -f,
                    b.addPoint(z, R),
                    b.addPoint(L, A),
                    b.addPoint(E, P),
                    !y.instersects(b))
                        continue;
                    for (l = 0,
                    c = w.meshMaterial.length; l < c; )
                        if (S = w.meshMaterial[l++],
                        S instanceof n.MeshFaceMaterial)
                            for (m = 0,
                            v = w.faceMaterial.length; m < v; )
                                S = w.faceMaterial[m++],
                                r(z, R, L, A, E, P, w, S, i);
                        else
                            r(z, R, L, A, E, P, w, S, i)
                } else if (w instanceof n.RenderableFace4) {
                    if (z = w.v1.x * u,
                    R = w.v1.y * -f,
                    L = w.v2.x * u,
                    A = w.v2.y * -f,
                    E = w.v3.x * u,
                    P = w.v3.y * -f,
                    C = w.v4.x * u,
                    B = w.v4.y * -f,
                    b.addPoint(z, R),
                    b.addPoint(L, A),
                    b.addPoint(E, P),
                    b.addPoint(C, B),
                    !y.instersects(b))
                        continue;
                    for (l = 0,
                    c = w.meshMaterial.length; l < c; )
                        if (S = w.meshMaterial[l++],
                        S instanceof n.MeshFaceMaterial)
                            for (m = 0,
                            v = w.faceMaterial.length; m < v; )
                                S = w.faceMaterial[m++],
                                s(z, R, L, A, E, P, C, B, w, S, i);
                        else
                            s(z, R, L, A, E, P, C, B, w, S, i)
                }
        }
    }
    ,
    n.WebGLRenderer = function() {
        function t() {
            try {
                o = a.getContext("experimental-webgl", {
                    antialias: !0
                })
            } catch (t) {}
            if (!o)
                throw alert("WebGL not supported"),
                "cannot create webgl context";
            o.clearColor(0, 0, 0, 1),
            o.clearDepth(1),
            o.enable(o.DEPTH_TEST),
            o.depthFunc(o.LEQUAL),
            o.enable(o.BLEND),
            o.blendFunc(o.ONE, o.ONE_MINUS_SRC_ALPHA),
            o.clearColor(0, 0, 0, 0)
        }
        function i() {
            r = o.createProgram(),
            o.attachShader(r, e("fragment", ["#ifdef GL_ES", "precision highp float;", "#endif", "uniform sampler2D diffuse;", "uniform vec4 uniformColor;", "varying vec2 vertexUv;", "varying vec3 lightWeighting;", "varying vec3 vNormal;", "uniform int material;", "uniform vec4 mAmbient;", "uniform vec4 mDiffuse;", "uniform vec4 mSpecular;", "uniform float mShininess;", "varying vec3 pLightVectorPoint;", "varying vec3 pLightVectorDirection;", "varying vec3 pViewPosition;", "void main(){", "if(material==3) { ", "vec3 lightVectorPoint = normalize(pLightVectorPoint);", "vec3 lightVectorDir = normalize(pLightVectorDirection);", "vec3 normal = normalize(vNormal);", "vec3 viewPosition = normalize(pViewPosition);", "vec3 halfVectorPoint = normalize(pLightVectorPoint + pViewPosition);", "float dotNormalHalfPoint = dot(normal, halfVectorPoint);", "float ambientCompPoint = 1.0;", "float diffuseCompPoint = max(dot(normal, lightVectorPoint), 0.0);", "float specularCompPoint = pow(dotNormalHalfPoint, mShininess);", "vec4 ambientPoint  = mAmbient * ambientCompPoint;", "vec4 diffusePoint  = mDiffuse * diffuseCompPoint;", "vec4 specularPoint = mSpecular * specularCompPoint;", "vec3 halfVectorDir = normalize(pLightVectorDirection + pViewPosition);", "float dotNormalHalfDir = dot(normal, halfVectorDir);", "float ambientCompDir = 1.0;", "float diffuseCompDir = max(dot(normal, lightVectorDir), 0.0);", "float specularCompDir = pow(dotNormalHalfDir, mShininess);", "vec4 ambientDir  = mAmbient * ambientCompDir;", "vec4 diffuseDir  = mDiffuse * diffuseCompDir;", "vec4 specularDir = mSpecular * specularCompDir;", "vec4 pointLight = ambientPoint + diffusePoint + specularPoint;", "vec4 dirLight = ambientDir + diffuseDir + specularDir;", "gl_FragColor = vec4((pointLight.xyz + dirLight.xyz) * lightWeighting, 1.0);", "} else if(material==2) {", "vec4 texelColor = texture2D(diffuse, vertexUv);", "gl_FragColor = vec4(texelColor.rgb * lightWeighting, texelColor.a);", "} else if(material==1) {", "gl_FragColor = vec4(uniformColor.rgb * lightWeighting, uniformColor.a);", "} else {", "gl_FragColor = vec4(uniformColor.rgb * lightWeighting, uniformColor.a);", "}", "}"].join("\n"))),
            o.attachShader(r, e("vertex", ["attribute vec3 position;", "attribute vec3 normal;", "attribute vec2 uv;", "uniform bool enableLighting;", "uniform vec3 ambientColor;", "uniform vec3 directionalColor;", "uniform vec3 lightingDirection;", "uniform vec3 pointColor;", "uniform vec3 pointPosition;", "uniform mat4 objMatrix;", "uniform mat4 viewMatrix;", "uniform mat4 modelViewMatrix;", "uniform mat4 projectionMatrix;", "uniform mat3 normalMatrix;", "varying vec4 vertexColor;", "varying vec2 vertexUv;", "varying vec3 lightWeighting;", "varying vec3 vNormal;", "varying vec3 pLightVectorPoint;", "varying vec3 pLightVectorDirection;", "varying vec3 pViewPosition;", "uniform vec3 cameraPosition;", "void main(void) {", "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );", "vec3 transformedNormal = normalize(normalMatrix * normal);", "vec4 lPosition = viewMatrix * vec4( pointPosition, 1.0 );", "vec4 lDirection = viewMatrix * vec4( lightingDirection, 0.0 );", "pLightVectorPoint = normalize(pointPosition.xyz - position.xyz);", "pLightVectorDirection = normalize(lDirection.xyz);", "vec4 mPosition = objMatrix * vec4( position, 1.0 );", "pViewPosition = cameraPosition - mPosition.xyz;", "if(!enableLighting) {", "lightWeighting = vec3(1.0, 1.0, 1.0);", "} else {", "vec3 pointLight = normalize(lPosition.xyz - mvPosition.xyz);", "float directionalLightWeighting = max(dot(transformedNormal, normalize(lDirection.xyz)), 0.0);", "float pointLightWeighting = max(dot(transformedNormal, pointLight), 0.0);", "lightWeighting = ambientColor + directionalColor * directionalLightWeighting + pointColor * pointLightWeighting;", "}", "vNormal = transformedNormal;", "vertexUv = uv;", "gl_Position = projectionMatrix * mvPosition;", "}"].join("\n"))),
            o.linkProgram(r),
            o.getProgramParameter(r, o.LINK_STATUS) || alert("Could not initialise shaders"),
            o.useProgram(r),
            r.viewMatrix = o.getUniformLocation(r, "viewMatrix"),
            r.modelViewMatrix = o.getUniformLocation(r, "modelViewMatrix"),
            r.projectionMatrix = o.getUniformLocation(r, "projectionMatrix"),
            r.normalMatrix = o.getUniformLocation(r, "normalMatrix"),
            r.objMatrix = o.getUniformLocation(r, "objMatrix"),
            r.enableLighting = o.getUniformLocation(r, "enableLighting"),
            r.ambientColor = o.getUniformLocation(r, "ambientColor"),
            r.directionalColor = o.getUniformLocation(r, "directionalColor"),
            r.lightingDirection = o.getUniformLocation(r, "lightingDirection"),
            r.pointColor = o.getUniformLocation(r, "pointColor"),
            r.pointPosition = o.getUniformLocation(r, "pointPosition"),
            r.material = o.getUniformLocation(r, "material"),
            r.uniformColor = o.getUniformLocation(r, "uniformColor"),
            r.mAmbient = o.getUniformLocation(r, "mAmbient"),
            r.mDiffuse = o.getUniformLocation(r, "mDiffuse"),
            r.mSpecular = o.getUniformLocation(r, "mSpecular"),
            r.mShininess = o.getUniformLocation(r, "mShininess"),
            r.cameraPosition = o.getUniformLocation(r, "cameraPosition"),
            r.position = o.getAttribLocation(r, "position"),
            o.enableVertexAttribArray(r.position),
            r.normal = o.getAttribLocation(r, "normal"),
            o.enableVertexAttribArray(r.normal),
            r.uv = o.getAttribLocation(r, "uv"),
            o.enableVertexAttribArray(r.uv),
            r.diffuse = o.getUniformLocation(r, "diffuse"),
            o.uniform1i(r.diffuse, 0),
            r.viewMatrixArray = new Float32Array(16),
            r.modelViewMatrixArray = new Float32Array(16),
            r.projectionMatrixArray = new Float32Array(16)
        }
        function e(t, i) {
            var n;
            return "fragment" == t ? n = o.createShader(o.FRAGMENT_SHADER) : "vertex" == t && (n = o.createShader(o.VERTEX_SHADER)),
            o.shaderSource(n, i),
            o.compileShader(n),
            o.getShaderParameter(n, o.COMPILE_STATUS) ? n : (alert(o.getShaderInfoLog(n)),
            null)
        }
        var o, r, s, a = document.createElement("canvas"), h = new n.Matrix4, l = 0, c = 1, u = 2, f = 3;
        this.domElement = a,
        this.autoClear = !0,
        t(),
        i(),
        this.setSize = function(t, i) {
            a.width = t,
            a.height = i,
            o.viewport(0, 0, a.width, a.height)
        }
        ,
        this.clear = function() {
            o.clear(o.COLOR_BUFFER_BIT | o.DEPTH_BUFFER_BIT)
        }
        ,
        this.setupLights = function(t) {
            var i, e, s, a, h, l;
            for (o.uniform1i(r.enableLighting, t.lights.length),
            i = 0,
            e = t.lights.length; i < e; i++)
                l = t.lights[i],
                l instanceof n.AmbientLight ? (s = l.color,
                o.uniform3f(r.ambientColor, s.r, s.g, s.b)) : l instanceof n.DirectionalLight ? (s = l.color,
                a = l.position,
                h = l.intensity,
                o.uniform3f(r.lightingDirection, a.x, a.y, a.z),
                o.uniform3f(r.directionalColor, s.r * h, s.g * h, s.b * h)) : l instanceof n.PointLight && (s = l.color,
                a = l.position,
                h = l.intensity,
                o.uniform3f(r.pointPosition, a.x, a.y, a.z),
                o.uniform3f(r.pointColor, s.r * h, s.g * h, s.b * h))
        }
        ,
        this.createBuffers = function(t, i) {
            var e, r, s, a, h, l, c, u, f, m, p, d = t.materialFaceGroup[i], x = [], g = [], v = [], y = [], b = [], M = 0;
            for (e = 0,
            r = d.faces.length; e < r; e++)
                s = d.faces[e],
                a = t.geometry.faces[s],
                h = a.vertexNormals,
                l = a.normal,
                c = t.geometry.uvs[s],
                a instanceof n.Face3 ? (u = t.geometry.vertices[a.a].position,
                f = t.geometry.vertices[a.b].position,
                m = t.geometry.vertices[a.c].position,
                v.push(u.x, u.y, u.z),
                v.push(f.x, f.y, f.z),
                v.push(m.x, m.y, m.z),
                3 == h.length ? (y.push(h[0].x, h[0].y, h[0].z),
                y.push(h[1].x, h[1].y, h[1].z),
                y.push(h[2].x, h[2].y, h[2].z)) : (y.push(l.x, l.y, l.z),
                y.push(l.x, l.y, l.z),
                y.push(l.x, l.y, l.z)),
                c && (b.push(c[0].u, c[0].v),
                b.push(c[1].u, c[1].v),
                b.push(c[2].u, c[2].v)),
                x.push(M, M + 1, M + 2),
                g.push(M, M + 1),
                g.push(M, M + 2),
                g.push(M + 1, M + 2),
                M += 3) : a instanceof n.Face4 && (u = t.geometry.vertices[a.a].position,
                f = t.geometry.vertices[a.b].position,
                m = t.geometry.vertices[a.c].position,
                p = t.geometry.vertices[a.d].position,
                v.push(u.x, u.y, u.z),
                v.push(f.x, f.y, f.z),
                v.push(m.x, m.y, m.z),
                v.push(p.x, p.y, p.z),
                4 == h.length ? (y.push(h[0].x, h[0].y, h[0].z),
                y.push(h[1].x, h[1].y, h[1].z),
                y.push(h[2].x, h[2].y, h[2].z),
                y.push(h[3].x, h[3].y, h[3].z)) : (y.push(l.x, l.y, l.z),
                y.push(l.x, l.y, l.z),
                y.push(l.x, l.y, l.z),
                y.push(l.x, l.y, l.z)),
                c && (b.push(c[0].u, c[0].v),
                b.push(c[1].u, c[1].v),
                b.push(c[2].u, c[2].v),
                b.push(c[3].u, c[3].v)),
                x.push(M, M + 1, M + 2),
                x.push(M, M + 2, M + 3),
                g.push(M, M + 1),
                g.push(M, M + 2),
                g.push(M, M + 3),
                g.push(M + 1, M + 2),
                g.push(M + 2, M + 3),
                M += 4);
            v.length && (d.__webGLVertexBuffer = o.createBuffer(),
            o.bindBuffer(o.ARRAY_BUFFER, d.__webGLVertexBuffer),
            o.bufferData(o.ARRAY_BUFFER, new Float32Array(v), o.STATIC_DRAW),
            d.__webGLNormalBuffer = o.createBuffer(),
            o.bindBuffer(o.ARRAY_BUFFER, d.__webGLNormalBuffer),
            o.bufferData(o.ARRAY_BUFFER, new Float32Array(y), o.STATIC_DRAW),
            d.__webGLUVBuffer = o.createBuffer(),
            o.bindBuffer(o.ARRAY_BUFFER, d.__webGLUVBuffer),
            o.bufferData(o.ARRAY_BUFFER, new Float32Array(b), o.STATIC_DRAW),
            d.__webGLFaceBuffer = o.createBuffer(),
            o.bindBuffer(o.ELEMENT_ARRAY_BUFFER, d.__webGLFaceBuffer),
            o.bufferData(o.ELEMENT_ARRAY_BUFFER, new Uint16Array(x), o.STATIC_DRAW),
            d.__webGLLineBuffer = o.createBuffer(),
            o.bindBuffer(o.ELEMENT_ARRAY_BUFFER, d.__webGLLineBuffer),
            o.bufferData(o.ELEMENT_ARRAY_BUFFER, new Uint16Array(g), o.STATIC_DRAW),
            d.__webGLFaceCount = x.length,
            d.__webGLLineCount = g.length)
        }
        ,
        this.renderBuffer = function(t, i) {
            t instanceof n.MeshPhongMaterial ? (mAmbient = t.ambient,
            mDiffuse = t.diffuse,
            mSpecular = t.specular,
            o.uniform4f(r.mAmbient, mAmbient.r, mAmbient.g, mAmbient.b, t.opacity),
            o.uniform4f(r.mDiffuse, mDiffuse.r, mDiffuse.g, mDiffuse.b, t.opacity),
            o.uniform4f(r.mSpecular, mSpecular.r, mSpecular.g, mSpecular.b, t.opacity),
            o.uniform1f(r.mShininess, t.shininess),
            o.uniform1i(r.material, f)) : t instanceof n.MeshColorFillMaterial ? (color = t.color,
            o.uniform4f(r.uniformColor, color.r * color.a, color.g * color.a, color.b * color.a, color.a),
            o.uniform1i(r.material, l)) : t instanceof n.MeshColorStrokeMaterial ? (lineWidth = t.lineWidth,
            color = t.color,
            o.uniform4f(r.uniformColor, color.r * color.a, color.g * color.a, color.b * color.a, color.a),
            o.uniform1i(r.material, c)) : t instanceof n.MeshBitmapMaterial && (!t.__webGLTexture && t.loaded && (t.__webGLTexture = o.createTexture(),
            o.bindTexture(o.TEXTURE_2D, t.__webGLTexture),
            o.texImage2D(o.TEXTURE_2D, 0, o.RGBA, o.RGBA, o.UNSIGNED_BYTE, t.bitmap),
            o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MAG_FILTER, o.LINEAR),
            o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MIN_FILTER, o.LINEAR_MIPMAP_LINEAR),
            o.generateMipmap(o.TEXTURE_2D),
            o.bindTexture(o.TEXTURE_2D, null)),
            o.activeTexture(o.TEXTURE0),
            o.bindTexture(o.TEXTURE_2D, t.__webGLTexture),
            o.uniform1i(r.diffuse, 0),
            o.uniform1i(r.material, u)),
            o.bindBuffer(o.ARRAY_BUFFER, i.__webGLVertexBuffer),
            o.vertexAttribPointer(r.position, 3, o.FLOAT, !1, 0, 0),
            o.bindBuffer(o.ARRAY_BUFFER, i.__webGLNormalBuffer),
            o.vertexAttribPointer(r.normal, 3, o.FLOAT, !1, 0, 0),
            t instanceof n.MeshBitmapMaterial ? (o.bindBuffer(o.ARRAY_BUFFER, i.__webGLUVBuffer),
            o.enableVertexAttribArray(r.uv),
            o.vertexAttribPointer(r.uv, 2, o.FLOAT, !1, 0, 0)) : o.disableVertexAttribArray(r.uv),
            t instanceof n.MeshBitmapMaterial || t instanceof n.MeshColorFillMaterial || t instanceof n.MeshPhongMaterial ? (o.bindBuffer(o.ELEMENT_ARRAY_BUFFER, i.__webGLFaceBuffer),
            o.drawElements(o.TRIANGLES, i.__webGLFaceCount, o.UNSIGNED_SHORT, 0)) : t instanceof n.MeshColorStrokeMaterial && (o.lineWidth(lineWidth),
            o.bindBuffer(o.ELEMENT_ARRAY_BUFFER, i.__webGLLineBuffer),
            o.drawElements(o.LINES, i.__webGLLineCount, o.UNSIGNED_SHORT, 0))
        }
        ,
        this.renderMesh = function(t, i) {
            var e, o, r, s, a, h, l, c;
            for (a in t.materialFaceGroup)
                for (c = t.materialFaceGroup[a],
                c.__webGLVertexBuffer || this.createBuffers(t, a),
                r = 0,
                s = t.material.length; r < s; r++)
                    if (l = t.material[r],
                    l instanceof n.MeshFaceMaterial)
                        for (e = 0,
                        o = c.material.length; e < o; e++)
                            h = c.material[e],
                            this.renderBuffer(h, c);
                    else
                        h = l,
                        this.renderBuffer(h, c)
        }
        ,
        this.setupMatrices = function(t, i) {
            t.autoUpdateMatrix && t.updateMatrix(),
            h.multiply(i.matrix, t.matrix),
            r.viewMatrixArray = new Float32Array(i.matrix.flatten()),
            r.modelViewMatrixArray = new Float32Array(h.flatten()),
            r.projectionMatrixArray = new Float32Array(i.projectionMatrix.flatten()),
            s = n.Matrix4.makeInvert3x3(h).transpose(),
            r.normalMatrixArray = new Float32Array(s.m),
            o.uniformMatrix4fv(r.viewMatrix, !1, r.viewMatrixArray),
            o.uniformMatrix4fv(r.modelViewMatrix, !1, r.modelViewMatrixArray),
            o.uniformMatrix4fv(r.projectionMatrix, !1, r.projectionMatrixArray),
            o.uniformMatrix3fv(r.normalMatrix, !1, r.normalMatrixArray),
            o.uniformMatrix4fv(r.objMatrix, !1, new Float32Array(t.matrix.flatten()))
        }
        ,
        this.render = function(t, i) {
            var e, s, a;
            for (this.autoClear && this.clear(),
            i.autoUpdateMatrix && i.updateMatrix(),
            o.uniform3f(r.cameraPosition, i.position.x, i.position.y, i.position.z),
            this.setupLights(t),
            e = 0,
            s = t.objects.length; e < s; e++)
                a = t.objects[e],
                this.setupMatrices(a, i),
                a instanceof n.Mesh ? this.renderMesh(a, i) : a instanceof n.Line || a instanceof n.Particle
        }
    }
    ,
    n.RenderableFace3 = function() {
        this.v1 = new n.Vector2,
        this.v2 = new n.Vector2,
        this.v3 = new n.Vector2,
        this.centroidWorld = new n.Vector3,
        this.normalWorld = new n.Vector3,
        this.z = null,
        this.color = null,
        this.material = null
    }
    ,
    n.RenderableFace4 = function() {
        this.v1 = new n.Vector2,
        this.v2 = new n.Vector2,
        this.v3 = new n.Vector2,
        this.v4 = new n.Vector2,
        this.centroidWorld = new n.Vector3,
        this.normalWorld = new n.Vector3,
        this.z = null,
        this.color = null,
        this.material = null
    }
    ,
    n.RenderableParticle = function() {
        this.x = null,
        this.y = null,
        this.z = null,
        this.rotation = null,
        this.scale = new n.Vector2,
        this.color = null,
        this.material = null
    }
    ,
    n.RenderableLine = function() {
        this.v1 = new n.Vector2,
        this.v2 = new n.Vector2,
        this.z = null,
        this.color = null,
        this.material = null
    };
    
    return n
}